<?php

		function process_payment( $environment, $api_username, $api_password, $api_signature, $proxy_server = '', $proxy_port = '' )
		{
				global $error;
				
				// Set request-specific fields.
				$paymentType = urlencode('Authorization');				// or 'Sale'
				$firstName = urlencode($_POST['BillingFirstName']);
				$lastName = urlencode($_POST['BillingLastName']);
				$creditCardType = urlencode($_POST['CreditCardType']);
				$creditCardNumber = urlencode($_POST['CreditCardNumber']);
				$expDateMonth = $_POST['ExpMonth'];
				// Month must be padded with leading zero
				$padDateMonth = urlencode(str_pad($expDateMonth, 2, '0', STR_PAD_LEFT));
				$expDateYear = urlencode($_POST['ExpYear']);
				$cvv2Number = urlencode($_POST['CVV2']);
				$address1 = urlencode($_POST['BillingStreet1']);
				$address2 = urlencode($_POST['BillingStreet2']);
				$city = urlencode($_POST['BillingCityName']);
				$state = urlencode($_POST['BillingStateOrProvince']);
				$zip = urlencode($_POST['BillingPostalCode']);
				$country = urlencode($_POST['BillingCountry']);				// US or other valid country code
				$amount = urlencode($_POST['amount']);
				$currencyID = urlencode($_POST['currency_code']);							// USD or other currency ('GBP', 'EUR', 'JPY', 'CAD', 'AUD')

				// Add request-specific fields to the request string.
				$nvpStr =	"&PAYMENTACTION=$paymentType&AMT=$amount&CREDITCARDTYPE=$creditCardType&ACCT=$creditCardNumber".
							"&EXPDATE=$padDateMonth$expDateYear&CVV2=$cvv2Number&FIRSTNAME=$firstName&LASTNAME=$lastName".
							"&STREET=$address1&CITY=$city&STATE=$state&ZIP=$zip&COUNTRYCODE=$country&CURRENCYCODE=$currencyID";
				
				// Execute the API operation; see the PPHttpPost function above.
				$httpParsedResponseAr = PPHttpPost('DoDirectPayment', $nvpStr, $environment, $api_username, $api_password, $api_signature, $proxy_server, $proxy_port);
				
				if("Success" == $httpParsedResponseAr["ACK"]) 
				{
						header("Location: payment_success.php?transID={$httpParsedResponseAr['TRANSACTIONID']}&return={$_POST['return']}");
						//exit('Direct Payment Completed Successfully: '.print_r($httpParsedResponseAr, true));
				} 
				else  
				{
						$error = urldecode($httpParsedResponseAr["L_LONGMESSAGE0"]);
						//exit('DoDirectPayment failed: ' . print_r($httpParsedResponseAr, true));
				}
		}

?>